//
//  SGSpecificTableViewCell.swift
//  songguo
//
//  Created by 潘传洲 on 16/6/13.
//  Copyright © 2016年 pcz. All rights reserved.
//

import UIKit
import SDWebImage

class SGSpecificTableViewCell: UITableViewCell {

    lazy var txtLabel: UILabel = {
        let txtLabel = UILabel()
        txtLabel.numberOfLines = 0
        return txtLabel
    }()
    
    var contentImageView: UIImageView = {
        let contentImageView = UIImageView()
        return contentImageView
    }()
    
    
    var specificViewModel : SGSpecificViewModel?{
        didSet{
            dealData()
        }
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        contentView.addSubview(txtLabel)
        contentView.addSubview(contentImageView)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func setSelected(selected: Bool, animated: Bool) {
    }
    
    
    override func setHighlighted(highlighted: Bool, animated: Bool) {
        
    }
    
    func dealData() {
        
        let resourceModel = specificViewModel!.resourceModel!
        
        if resourceModel.tp == .Text {
            contentImageView.hidden = true
            txtLabel.hidden = false
            let frame = CGRect(x: 10, y: 0, width: screenWidth - 2 * margin, height: specificViewModel!.labelHeight)
            txtLabel.frame = frame
            if resourceModel.isSubTitle {
                txtLabel.font = UIFont.systemFontOfSize(14, weight: 6)
            }else{
                txtLabel.font = UIFont.systemFontOfSize(14)
            }
            txtLabel.text = resourceModel.txt
        }else{
            contentImageView.hidden = false
            txtLabel.hidden = true
            let frame = CGRect(x: 10, y: 0, width: screenWidth - 2 * margin, height: specificViewModel!.imageViewHeight)
            contentImageView.frame = frame
            contentImageView.sd_setImageWithURL(NSURL(string: resourceModel.url!), placeholderImage: UIImage(named: "home_cell_placeholderImage"))
        }
    }
}
